var roleList = {};
var RoleList = function () {
    //初始化表格
  this.init = function () {
      layuiFunciton.tableInit({
          toolbar:'.btn',
          tableId: 'roleTableId',
          url:  layuiFunciton.URL + '/sysRole/findRoleList',
          id: 'roleId',
          searchFromId:'formRole',
          tableFilter:'roleFilter',  //表格监听名称,
          //limit:3,
          cols: [[
              {type:'numbers',title: '序号',fixed: 'left'},
              {field:'roleName', title: '角色名称', sort: true}
              ,{field:'roleCode', title: '角色编号', sort: true}
              ,{field:'userNumber', title: '使用人数', sort: true,templet:function (data) {
                  if(data.userNumber!=null)
                      return data.userNumber;
                  else
                      return "0";
              }}
              ,{field:'createTime', title: '创建时间', sort: true}
          ]],
          tools:{
              edit:function (rowData) {
                  //初始化权限
                  layuiFunciton.ajaxRequest({
                      url: layuiFunciton.URL + '/sysRole/findAutorityAll',
                      method: 'post',
                      data: {roleId: rowData.id},
                      success: function (returnData) {
                          console.log(returnData);
                          rowData.menuList=returnData;
                      }
                  });
                  layuiFunciton.layerOpen({title:"修改",finder:'form',content:"edit.html",data:rowData,end:function () {
                      layuiFunciton.refresh('formRole','roleId');
                  }});
              }
              ,del:function (rowData) {
                  if(rowData.userNumber>0){
                      layuiFunciton.warn("角色已被使用，无法删除！");
                  }else{
                      layuiFunciton.alert({
                          types: 'confirm',
                          title: '是否删除？',
                          success: function () {
                              layuiFunciton.ajaxRequest({
                                  url: layuiFunciton.URL + '/sysRole/editSysAuthority',
                                  method:'post',
                                  data:{id:rowData.id,delFlag:1},
                                  success:function (data) {
                                      layuiFunciton.refresh('formRole','roleId');
                                  }
                              });
                          }
                      });
                  }
              }
              ,addRole:function (rowData) {
                  layuiFunciton.layerOpen({title:"添加",content:"add.html",end:function () {
                      layuiFunciton.refresh('formRole','roleId');
                  }});
              }
          }
      });
  };
  //事件绑定
  this.listening = function () {
      //搜索
      $("#find").click(function () {
          layuiFunciton.refresh("formRole","roleId",1);
      });
  };
};
$(function () {
    roleList = new RoleList();
    roleList.init();
    roleList.listening();
});
